#include "../src/server.hpp"

void OnMessage(const PtrConnection& conn, Buffer* buffer)
{
    DBG_LOG("buffer: %s", buffer->ReadPosition());
    buffer->MoveReadOffset(buffer->ReadAbleSize());
    std::string str = "hello world!";
    conn->Send(str.c_str(), str.size());
    // conn->ShutDown();
}
void OnClose(const PtrConnection& conn)
{
    DBG_LOG("close connection: %p", conn.get());
}
void OnConnected(const PtrConnection& conn)
{
    DBG_LOG("new connection: %p", conn.get());
}

int main()
{
    TcpServer server(9000);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(10);

    server.SetCloseCallback(OnClose);
    server.SetConnectedCallback(OnConnected);
    server.SetMessageCallback(OnMessage);

    server.Start();

    return 0;
}